let vm =new Vue({
    el:"#app",
    data:{
        shoop:[
            {id:1,name:"苹果12",time:new Date(),price:8765,count:1},
            {id:2,name:"苹果8",time:new Date(),price:7756,count:1},
            {id:3,name:"苹果6",time:new Date(),price:4888,count:1},
            {id:4,name:"华为",time:new Date(),price:3999,count:1}
        ],
        shoopName:null,
        shoopPrice:null,
        key:''
    },
    methods:{
        add(){
            let id = [this.shoop.length-1].id+1
            this.shoop.push({
                id:id,
                name:this.shoopName,
                time:new Date(),
                price:this.shoopPrice,
                count:1
            })
            this.shoopName=null,
            this.shoopPrice=null
        },
        delet(index){
            this.shoop.splice(index,1)
        },
        decreame(item){
            item.count--
        },
        increame(item){
            item.count++
        }
    },
    filters:{
        dateFormat(date){
            let dateObj = new Date(date)
            let fullYear = dateObj.getFullYear()
            let month = (dateObj.getMonth()+1).toString().padStart(2,0)
            let day = dateObj.getDate().toString().padStart(2,0)
            let hour = dateObj.getHours().toString().padStart(2,0)
            let minute = dateObj.getMinutes().toString().padStart(2,0)
            let seconds = dateObj.getSeconds().toString().padStart(2,0)

            return `${fullYear}-${month}-${day} ${hour}:${minute}:${seconds}`
        },
        moenyFlag(text){
            //   console.log(typeof text);
            return "￥"+Number(text).toFixed(2)
    
          }
    },
    computed: {
        search(){
            return this.shoop.filter((item)=>{
                return item.name.includes(this.key)
            })
        },
        totalPrice(){
            let total =0
            this.shoop.forEach((item)=>{
                total+= item.price * item.count
            })
            return total
        }
    },
})